#include "StdAfx.h"
#include ".\mfcwpfelement.h"

CMFCWPFElement::CMFCWPFElement(void)
{
}

CMFCWPFElement::~CMFCWPFElement(void)
{
}

///<summary>
///Get Node Attributes from the xaml file using the path
///</summary>
///<param name='szPath'>
///the path in the xaml file
///</param>
///<param name='pXmlParser'>
///the pointer to the xml parser
///</param>
///<param name='oRect'>
///the region of the element that contains this element
///</param>
void CMFCWPFElement::Parse(const CString & szPath, CECGXmlParser * pXamlParser, const CRect & /*oRect*/)
{
	CECGXmlNode oNode;
	pXamlParser->ParseNode(oNode, szPath);
	m_szType = oNode.GetName().MakeLower();
	for (int nAttributesIndex = 0; nAttributesIndex < oNode.GetAttributesCount(); ++nAttributesIndex)
	{
		m_oAttributes.InsertAttribute(oNode.GetAttribute(nAttributesIndex)->GetName(), oNode.GetAttribute(nAttributesIndex)->GetValue());
	}
}

///<summary>
///Draw the element in the context of pCDCPlus according to the "IsEnabled" attribute
///</summary>
///<param name='pCDCPlus'>
///the pointer to the GDI+ display context
///</param>
///<returns>
///true if the element is enabled; false otherwise
///</returns>
bool CMFCWPFElement::DrawSelf(CDCPlus * /*pCDCPlus*/)
{
	return IsEnabled();
}

///<summary>
///the element is clicked or not
///</summary>
///<param name='nFlags'>
///show if there is other keys pushing down
///</param>
///<param name='oPoint'>
///the pointer 
///</param>
///<returns>
///the pointer to the element
///</returns>
CMFCWPFElement * CMFCWPFElement::MouseLeftButtonUp(int /*nFlags*/, const CPoint & /*oPoint*/)
{
	return NULL;
}

///<summary>
///Get element's Type
///</summary>
///<returns>
///The element's Type attribute value
///</returns>
CString CMFCWPFElement::GetElementType()
{
	return m_szType;
}

///<summary>
///Get element's Name
///</summary>
///<returns>
///The element's Name attribute value
///</returns>
CString CMFCWPFElement::GetElementName()
{
	CString szValue;
	m_oAttributes.GetAttribute(_ATTRIBUTENAME, szValue);
	return szValue;
}

///<summary>
///get "items" attribute value from m_oAttributes
///</summary>
bool CMFCWPFElement::GetItems(vector<CString> & szVec)
{
	return m_oAttributes.GetItems(szVec);
}

///<summary>
///If the element is enabled
///</summary>
///<returns>
///true if it is; false othrwise
///</returns>
bool CMFCWPFElement::IsEnabled()
{
	CString szIsEnabled;
	m_oAttributes.GetAttribute(_ATTRIBUTEISENABLED, szIsEnabled);
	return !(szIsEnabled == _ATTRIBUTEVALUEFALSE);
}

///<summary>
///If the element is enabled
///</summary>
///<returns>
///true if it is; false othrwise
///</returns>
bool CMFCWPFElement::IsVisible()
{
	CString szVisibility;
	m_oAttributes.GetAttribute(_ATTRIBUTEISVISIBILITY, szVisibility);
	return !(szVisibility == _ATTRIBUTEVALUEHIDDEN);
}